package com.angel.email;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.mail.EmailException;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.angel.architecture.BaseArchitectureTestCase;
import com.angel.email.account.AccountInformation;
import com.angel.email.account.impl.MockAccountInformation;
import com.angel.email.builder.EmailBuilder;
import com.angel.email.builder.impl.SimpleEmailBuilder;
import com.angel.email.configuration.builders.EmailConfigurationBuilder;
import com.angel.email.configuration.builders.OutgoingEmailConfigurationBuilder;
import com.angel.email.configuration.builders.impl.yahoo.YahooOutgoingEmailConfigurationBuilder;
import com.angel.email.services.EmailService;

/**
 *
 * @author William
 *
 */
public class OutgoingEmailTestCase extends BaseArchitectureTestCase {

	@Autowired
	private EmailService emailService;

	@Test
	public void testSendEmail() throws EmailException{
		AccountInformation accountInfo = new MockAccountInformation("guillesalazar1983@yahoo.com.ar", "GUILLE1983");
		EmailConfigurationBuilder ecb = new EmailConfigurationBuilder(Boolean.FALSE);
		ecb.setOutgoingConfigurationBuilder(new YahooOutgoingEmailConfigurationBuilder(accountInfo));
		OutgoingEmailConfigurationBuilder outgoingConfBuilder = ecb.getOutgoingConfigurationBuilder();
		List<String> toEmails = new ArrayList<String>();
		toEmails.add("guillesalazar@gmail.com");
		String message = "Mesaje de prueba de envio de emails.";
		String subject = "Asunto de envio de email.";
		EmailBuilder emailBuilder = new SimpleEmailBuilder(outgoingConfBuilder, message, toEmails, subject);

		this.getEmailService().sendEmail(emailBuilder);
	}

	/**
	 * @return the emailService
	 */
	protected EmailService getEmailService() {
		return emailService;
	}

	/**
	 * @param emailService the emailService to set
	 */
	protected void setEmailService(EmailService emailService) {
		this.emailService = emailService;
	}


}
